from finder import Finder
import tools
import pytesseract
from PIL import Image


class ImageFinder(Finder):
    @staticmethod
    def file_suffixes():
        return [".png", ".jpg"]

    def search_file(self, file_path, search_content):
        if Finder.should_file_path_ignore(file_path):
            return

        image = Image.open(file_path)
        # 使用 PyTesseract 识别图像中的文字
        text = pytesseract.image_to_string(image, lang='chi_sim')
        with tools.lock:
            tools.global_store[f'{file_path}'] = text
        pass

        if search_content.lower() in Finder.process_text_if_need(text.lower()):
            print(f"Found '{search_content}' in {file_path}")
